namespace KPIS.GERP.Models.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class update0004 : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.SysUserLoginMonitor",
                c => new
                    {
                        UserId = c.Int(nullable: false),
                        ClientIp = c.String(nullable: false, maxLength: 128),
                        SystemId = c.String(nullable: false, maxLength: 128),
                        UserCode = c.String(),
                        FullName = c.String(),
                        PosId = c.Int(),
                        CurrentStatus = c.String(),
                        DateTimeInit = c.DateTime(nullable: false),
                        Icon = c.String(),
                    })
                .PrimaryKey(t => new { t.UserId, t.ClientIp, t.SystemId });
            
            CreateTable(
                "dbo.SysUserLoginLogout",
                c => new
                    {
                        UserId = c.Int(nullable: false),
                        ClientIp = c.String(nullable: false, maxLength: 128),
                        SystemId = c.String(nullable: false, maxLength: 128),
                        UserCode = c.String(),
                        FullName = c.String(),
                        PosId = c.Int(),
                        LoginDateTime = c.DateTime(nullable: false),
                        LogoutDateTime = c.DateTime(),
                    })
                .PrimaryKey(t => new { t.UserId, t.ClientIp, t.SystemId });
            
            CreateTable(
                "dbo.SysOTP",
                c => new
                    {
                        UniqueId = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => t.UniqueId);
            
            CreateTable(
                "dbo.sys_sc_users",
                c => new
                    {
                        user_seq = c.Int(nullable: false, identity: true),
                        emp_seq = c.Int(),
                        user_job_site_seq = c.Int(),
                        pos_seq = c.Int(),
                        user_code = c.String(nullable: false),
                        user_password = c.String(),
                        is_admin = c.Boolean(nullable: false),
                        user_citizen = c.String(),
                        user_status = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.user_seq)
                .ForeignKey("dbo.hrm_ps_employees", t => t.emp_seq)
                .ForeignKey("dbo.hrm_job_site", t => t.user_job_site_seq)
                .ForeignKey("dbo.hrm_position", t => t.pos_seq)
                .Index(t => t.emp_seq)
                .Index(t => t.user_job_site_seq)
                .Index(t => t.pos_seq);
            
            CreateTable(
                "dbo.SysMessage",
                c => new
                    {
                        MessageId = c.Int(nullable: false, identity: true),
                        Code = c.String(),
                        Date = c.DateTime(),
                        Title = c.String(),
                        Description = c.String(),
                        FromEmpId = c.Int(),
                        ToEmpId = c.Int(),
                        FromMessageID = c.Int(),
                        ApprovalTaskID = c.Int(),
                        RuleApproveID = c.Int(),
                        Remarks = c.String(),
                        MessageStatus = c.Int(nullable: false),
                        ActionCount = c.Int(nullable: false),
                        RuleApprove = c.Int(nullable: false),
                        ApprovalTask = c.Int(nullable: false),
                        RecordStatus = c.String(),
                        CreatedBy = c.Int(),
                        CreatedWhen = c.DateTime(),
                        UpdatedBy = c.Int(),
                        UpdatedWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.MessageId)
                .ForeignKey("dbo.hrm_ps_employees", t => t.FromEmpId)
                .ForeignKey("dbo.hrm_ps_employees", t => t.ToEmpId)
                .Index(t => t.FromEmpId)
                .Index(t => t.ToEmpId);
            
            CreateTable(
                "dbo.Message",
                c => new
                    {
                        MessageId = c.Int(nullable: false, identity: true),
                        MessageNo = c.String(),
                        MessageDate = c.DateTime(),
                        MessageTitle = c.String(),
                        MessageDescr = c.String(),
                        FromEmpId = c.Int(),
                        ToEmpId = c.Int(),
                        FromMessageId = c.Int(),
                        ApprovalTaskId = c.Int(),
                        ApprovalTaskHistoryId = c.Int(),
                        RuleApproveId = c.Int(),
                        Remarks = c.String(),
                        MessageStatus = c.String(),
                        RecordStatus = c.String(),
                        CreatedBy = c.Int(),
                        CreatedWhen = c.DateTime(),
                        UpdatedBy = c.Int(),
                        UpdatedWhen = c.DateTime(),
                        ActionCount = c.Int(),
                    })
                .PrimaryKey(t => t.MessageId);
            
            CreateTable(
                "dbo.MessageWarning",
                c => new
                    {
                        MessageId = c.Int(nullable: false, identity: true),
                        MessageTh = c.String(),
                        MessageEn = c.String(),
                        MessageType = c.String(),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreatedBy = c.Int(),
                        CreatedWhen = c.DateTime(),
                        UpdatedBy = c.Int(),
                        UpdatedWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.MessageId);
            
            CreateTable(
                "dbo.MessageSend",
                c => new
                    {
                        SendId = c.Int(nullable: false, identity: true),
                        SendDate = c.DateTime(nullable: false),
                        RefId = c.Int(),
                        RefType = c.String(),
                        RefNo = c.String(),
                        SendText = c.String(),
                        FromEmpId = c.Int(),
                        ToEmpId = c.Int(),
                        FromSendId = c.Int(),
                        Remarks = c.String(),
                        MessageStatus = c.String(),
                        RecordStatus = c.String(),
                        CreatedBy = c.Int(),
                        CreatedWhen = c.DateTime(),
                        UpdatedBy = c.Int(),
                        UpdatedWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.SendId);
            
            CreateTable(
                "dbo.MessageReply",
                c => new
                    {
                        ReplyId = c.Int(nullable: false, identity: true),
                        ReplyDate = c.DateTime(),
                        RefNo = c.String(),
                        ReplyType = c.String(),
                        ReplyText = c.String(),
                        FromEmpId = c.Int(),
                        ToEmpId = c.Int(),
                        FromSendId = c.Int(),
                        Remarks = c.String(),
                        MessageStatus = c.String(),
                        RecordStatus = c.String(),
                        CreatedBy = c.Int(),
                        CreatedWhen = c.DateTime(),
                        UpdatedBy = c.Int(),
                        UpdatedWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.ReplyId);
            
            CreateTable(
                "dbo.SysMenuItemList",
                c => new
                    {
                        MenuItemId = c.Int(nullable: false, identity: true),
                        MenuItemCode = c.String(),
                        MenuItemName = c.String(),
                        UpperMenuItemId = c.String(),
                        MenuItemPath = c.String(),
                        MenuItemTarget = c.String(),
                        SystemId = c.String(),
                        RecordStatus = c.String(),
                        CreatedBy = c.Int(),
                        CreatedWhen = c.DateTime(),
                        UpdatedBy = c.Int(),
                        UpdatedWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.MenuItemId);
            
            CreateTable(
                "dbo.sys_sc_roles",
                c => new
                    {
                        role_seq = c.Int(nullable: false, identity: true),
                        role_name = c.String(),
                        system = c.String(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.role_seq);
            
            CreateTable(
                "dbo.sys_sc_user_roles",
                c => new
                    {
                        user_role_seq = c.Int(nullable: false, identity: true),
                        user_seq = c.Int(nullable: false),
                        pos_seq = c.Int(),
                        role_seq = c.Int(nullable: false),
                        emp_type_seq = c.Int(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.user_role_seq)
                .ForeignKey("dbo.sys_sc_users", t => t.user_seq, cascadeDelete: true)
                .ForeignKey("dbo.hrm_position", t => t.pos_seq)
                .ForeignKey("dbo.sys_sc_roles", t => t.role_seq, cascadeDelete: true)
                .ForeignKey("dbo.hrm_mas_employee_type", t => t.emp_type_seq)
                .Index(t => t.user_seq)
                .Index(t => t.pos_seq)
                .Index(t => t.role_seq)
                .Index(t => t.emp_type_seq);
            
            CreateTable(
                "dbo.sys_sc_permissions",
                c => new
                    {
                        permission_seq = c.Int(nullable: false, identity: true),
                        role_seq = c.Int(nullable: false),
                        menu_item_seq = c.Int(nullable: false),
                        permission_type = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.permission_seq)
                .ForeignKey("dbo.sys_sc_roles", t => t.role_seq, cascadeDelete: true)
                .ForeignKey("dbo.sys_menu_items_list", t => t.menu_item_seq, cascadeDelete: true)
                .Index(t => t.role_seq)
                .Index(t => t.menu_item_seq);
            
            CreateTable(
                "dbo.sys_menu_items_list",
                c => new
                    {
                        menu_item_seq = c.Int(nullable: false, identity: true),
                        menu_item_code = c.String(),
                        menu_item_name = c.String(),
                        upper_menu_item_seq = c.Int(),
                        menu_item_path = c.String(),
                        menu_item_target = c.String(),
                        system_id = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.menu_item_seq);
            
            CreateTable(
                "dbo.sys_system_controls",
                c => new
                    {
                        dep_job_site_seq = c.Int(nullable: false, identity: true),
                        system_name = c.String(),
                    })
                .PrimaryKey(t => t.dep_job_site_seq);
            
            CreateTable(
                "dbo.sys_route_status",
                c => new
                    {
                        route_status = c.Int(nullable: false, identity: true),
                        route_status_name = c.String(),
                    })
                .PrimaryKey(t => t.route_status);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.sys_sc_permissions", new[] { "menu_item_seq" });
            DropIndex("dbo.sys_sc_permissions", new[] { "role_seq" });
            DropIndex("dbo.sys_sc_user_roles", new[] { "emp_type_seq" });
            DropIndex("dbo.sys_sc_user_roles", new[] { "role_seq" });
            DropIndex("dbo.sys_sc_user_roles", new[] { "pos_seq" });
            DropIndex("dbo.sys_sc_user_roles", new[] { "user_seq" });
            DropIndex("dbo.SysMessage", new[] { "ToEmpId" });
            DropIndex("dbo.SysMessage", new[] { "FromEmpId" });
            DropIndex("dbo.sys_sc_users", new[] { "pos_seq" });
            DropIndex("dbo.sys_sc_users", new[] { "user_job_site_seq" });
            DropIndex("dbo.sys_sc_users", new[] { "emp_seq" });
            DropForeignKey("dbo.sys_sc_permissions", "menu_item_seq", "dbo.sys_menu_items_list");
            DropForeignKey("dbo.sys_sc_permissions", "role_seq", "dbo.sys_sc_roles");
            DropForeignKey("dbo.sys_sc_user_roles", "emp_type_seq", "dbo.hrm_mas_employee_type");
            DropForeignKey("dbo.sys_sc_user_roles", "role_seq", "dbo.sys_sc_roles");
            DropForeignKey("dbo.sys_sc_user_roles", "pos_seq", "dbo.hrm_position");
            DropForeignKey("dbo.sys_sc_user_roles", "user_seq", "dbo.sys_sc_users");
            DropForeignKey("dbo.SysMessage", "ToEmpId", "dbo.hrm_ps_employees");
            DropForeignKey("dbo.SysMessage", "FromEmpId", "dbo.hrm_ps_employees");
            DropForeignKey("dbo.sys_sc_users", "pos_seq", "dbo.hrm_position");
            DropForeignKey("dbo.sys_sc_users", "user_job_site_seq", "dbo.hrm_job_site");
            DropForeignKey("dbo.sys_sc_users", "emp_seq", "dbo.hrm_ps_employees");
            DropTable("dbo.sys_route_status");
            DropTable("dbo.sys_system_controls");
            DropTable("dbo.sys_menu_items_list");
            DropTable("dbo.sys_sc_permissions");
            DropTable("dbo.sys_sc_user_roles");
            DropTable("dbo.sys_sc_roles");
            DropTable("dbo.SysMenuItemList");
            DropTable("dbo.MessageReply");
            DropTable("dbo.MessageSend");
            DropTable("dbo.MessageWarning");
            DropTable("dbo.Message");
            DropTable("dbo.SysMessage");
            DropTable("dbo.sys_sc_users");
            DropTable("dbo.SysOTP");
            DropTable("dbo.SysUserLoginLogout");
            DropTable("dbo.SysUserLoginMonitor");
        }
    }
}
